using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

namespace Janus.NorthwindDemo2007
{
	public class EmployeesDataProvider : DataProvider
	{



		internal Janus.NorthwindDemo2007.NorthwindDataTableAdapters.EmployeesTableAdapter EmployeesTableAdapter1;

		protected override bool FillCore()
		{
			this.EmployeesTableAdapter1.Fill(this.DataSet.Employees);
			return true;
		}
		protected override bool UpdateCore()
		{
			this.EmployeesTableAdapter1.Update(this.DataSet.Employees);
			return true;
		}
		protected override bool UpdateDataRowCore(System.Data.DataRow row)
		{
			this.EmployeesTableAdapter1.Update(row);
			return true;
		}

		public EmployeesDataProvider() : base()
		{
			this.EmployeesTableAdapter1 = new Janus.NorthwindDemo2007.NorthwindDataTableAdapters.EmployeesTableAdapter();
			this.EmployeesTableAdapter1.ClearBeforeFill = true;

			this.DataAdapter = this.EmployeesTableAdapter1.DataAdapter;
		}

		protected override void OnRowUpdated(System.Data.OleDb.OleDbRowUpdatedEventArgs e)
		{
			//this is done with tables that have autonumber fields
			if (e.Status != UpdateStatus.ErrorsOccurred)
			{

				// Include a variable and a command to retrieve the identity value from the Access database.
				int newID = 0;
				System.Data.OleDb.OleDbCommand idCMD = null;

				if (e.StatementType == StatementType.Insert)
				{
					idCMD = new System.Data.OleDb.OleDbCommand("SELECT @@IDENTITY", this.EmployeesTableAdapter1.Connection);
					// Retrieve the identity value and store it in the CategoryID column.
					newID = System.Convert.ToInt32(idCMD.ExecuteScalar());
					e.Row["EmployeeID"] = newID;
					idCMD.Dispose();
				}
			}
			base.OnRowUpdated(e);
		}

	}

} //end of root namespace